package cn.iocoder.yudao.module.famous.doctor.controller.app.researchgroup;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.famous.doctor.controller.admin.researchgroup.vo.*;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.researchgroup.ResearchgroupDO;
import cn.iocoder.yudao.module.famous.doctor.convert.researchgroup.ResearchgroupConvert;
import cn.iocoder.yudao.module.famous.doctor.service.researchgroup.ResearchgroupService;

@Tag(name = "用户 APP - 课题组")
@RestController
@RequestMapping("/famous.doctor/researchgroup/app")
@Validated
public class AppResearchgroupController {

    @Resource
    private ResearchgroupService researchgroupService;

    @PostMapping("/create")
    @Operation(summary = "创建课题组")
    public CommonResult<Long> createResearchgroup(@Valid @RequestBody ResearchgroupCreateReqVO createReqVO) {
        return success(researchgroupService.createResearchgroup(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新课题组")
    public CommonResult<Boolean> updateResearchgroup(@Valid @RequestBody ResearchgroupUpdateReqVO updateReqVO) {
        researchgroupService.updateResearchgroup(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除课题组")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteResearchgroup(@RequestParam("id") Long id) {
        researchgroupService.deleteResearchgroup(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得课题组")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<ResearchgroupRespVO> getResearchgroup(@RequestParam("id") Long id) {
        ResearchgroupDO researchgroup = researchgroupService.getResearchgroup(id);
        return success(ResearchgroupConvert.INSTANCE.convert(researchgroup));
    }

    @GetMapping("/list")
    @Operation(summary = "获得课题组列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<ResearchgroupRespVO>> getResearchgroupList(@RequestParam("ids") Collection<Long> ids) {
        List<ResearchgroupDO> list = researchgroupService.getResearchgroupList(ids);
        return success(ResearchgroupConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得课题组分页")
    public CommonResult<PageResult<ResearchgroupRespVO>> getResearchgroupPage(@Valid ResearchgroupPageReqVO pageVO) {
        PageResult<ResearchgroupDO> pageResult = researchgroupService.getResearchgroupPage(pageVO);
        return success(ResearchgroupConvert.INSTANCE.convertPage(pageResult));
    }

}
